﻿using SUNRPA.CONTROLS.IMPL.domain;
using SUNRPA.CONTROLS.IMPL.domain.flowItemParam;
using SUNRPA.CONTROLS.IMPL.domain.flowRunningVar;
using SUNRPA.CONTROLS.IMPL.util;
using System.Collections;
using System.Collections.Concurrent;

namespace SUNRPA.CONTROLS.IMPL.controls {
    public class MouseClickNAction:BaseControlActions {
        public override int Execute(int currentIndex, FlowItem item, ConcurrentDictionary<string, ConcurrentDictionary<string, RPAVariableDefineWrapper>> globleData, List<FlowItem> flowItems) {
            MouseClickNParam? param = item.ControlParam as MouseClickNParam;
            if(param.Move) { 
                MouseMoveNAction mva = new MouseMoveNAction();
                FlowItem tempItem = new FlowItem();
                tempItem.ControlParam = param.Mmp;
                mva.Execute(currentIndex, tempItem, globleData, flowItems);
                Thread.Sleep(1000);
            }
            if(param.ButtonType == 0) {
                //左键
                switch(param.ClickType) {
                    //单击
                    case 0 : 
                        User32Utils.LeftClick();
                        break;
                    //双击
                    case 1 :
                        User32Utils.LeftDoubleClick();
                        break;
                    case 2:
                        User32Utils.LeftDown();
                        break;
                    case 3:
                        User32Utils.LeftUp();
                        break;
                }
            } else { 
                //右键
                switch(param.ClickType) {
                    //单机
                    case 0 : 
                        User32Utils.RightClick();
                        break;
                    //双击
                    case 1 :
                        User32Utils.RightDoubleClick();
                        break;
                    //按下
                    case 2:
                        User32Utils.RightDown();
                        break;
                    //弹起
                    case 3:
                        User32Utils.RightUp();
                        break;
                }
            }
            return currentIndex;
        }
    }
}
